package com.fan.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fan.dao.CourseDao;
import com.fan.service.CourseService;
import com.fan.utils.CommonResults;
import com.sixth.entity.Course;
import com.sixth.entity.Order;
import com.sixth.until.CommonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: self-tui-education
 * @description:
 * @author: 老范
 * @create: 2022-04-18 09:15
 **/
@Service
public class CourseServiceImpl extends ServiceImpl<CourseDao, Course> implements CourseService {
    @Autowired
    private CourseDao courseDao;

    @Override
    public List<Course> findCourseId(String courseId) {
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("id",courseId);
        Course selectById = courseDao.selectOne(wrapper);
        List<Course> courses = new ArrayList<>();
        courses.add(selectById);
        System.out.println(selectById);
        return courses;
    }


    //根据课程id查询学生和教师信息
    @Override
    public CommonResult queryAllCourseAndTeacherName(String id) {
        List<Course> CoursesAndTeachername = courseDao.courseAndTeachername(id);
        return new CommonResult(2000,"查询成功",CoursesAndTeachername);
    }

    //根据课程id查询章节和课时信息
    @Override
    public CommonResult findChapterById(String id) {
        List<Course> findChapterById = courseDao.findChapterById(id);

        return new CommonResult(2000,"查询成功",findChapterById);
    }

    @Override
    public CommonResults queryAllById(String id, String mobile) {
        List<Course> courses = courseDao.queryAllById(id,mobile);

        if (courses.size()>0){
            return new CommonResults(2000,"查询成功",courses);
        }
        return new CommonResults(5000,"查询成功",null);
    }

    @Override
    public CommonResults queryMemberStatus(String id, String mobile) {
        com.fan.entity.Course course = courseDao.queryMemberStatus(id, mobile);
        if (course!=null){
            return new CommonResults(2000,"查询成功",course);
        }
        return new CommonResults(5000,"查询成功",null);
    }

}

